<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>采购单</title>
<link href="../../css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../../script/My97DatePicker/WdatePicker.js" ></script>
<script type="text/javascript" src="../../script/jquery-1.8.1.min.js" ></script>
<script language="javascript">
	function del(obj){
		if(confirm("确认删除吗？")){
			var tr = obj.parentNode.parentNode;
			var poId = tr.cells[0].innerHTML;
			window.location.href="DelPomain?poId="+poId+"&currentPage="+${page.currentPage};
		}
	}
	function goPage(currentPage){
		window.location.href = "ListNewPomain?currentPage="+currentPage;
	}
	function showVender(){
		document.getElementById("vender").style.display="block";
		document.getElementById("main").style.display="none";
		queryVender();
	}
	var currentPage=1;
	function queryVender(){
		$.ajax({
			type:"post",
			url:"main/pomain/ListAllVender",
			data:{currentPage:currentPage},
			dataType:"json",
			success:function(msg){
				$("#tvender").children().remove();
				for(var i=0;i<msg.dataList.length;i++){ 
					$("#tvender").append("<tr align='center'><td>"+msg.dataList[i].venderCode+"</td><td>"
							+msg.dataList[i].name+"</td><td><input type='button' value='选择' onclick='chooseVender(this)'/></td></tr>");
				}
				$("#vc").text(msg.currentPage);
				$("#va").text(msg.pageCount);
			}
		});
	}
	function chooseVender(obj){
		$("[name=venderName]").val(obj.parentNode.parentNode.cells[1].innerHTML);
		$("[name=venderCode]").val(obj.parentNode.parentNode.cells[0].innerHTML);
		document.getElementById("vender").style.display="none";
		document.getElementById("main").style.display="block";
	}
	function goback(){
		document.getElementById("vender").style.display="none";
		document.getElementById("main").style.display="block";
		document.getElementById("product").style.display="none";
	}
	function vendergoPage(obj){
		if(obj=='first'){
			currentPage=1;
			queryVender();
		}else if(obj=='front'){
			if(currentPage==1){
				alert("已经是首页了");
			}else{
				currentPage-=1;
				queryVender();
			} 
		}else if(obj=='next'){
			if(currentPage==$("#ap").text()){
				alert("已经是末页了");
			}else{
				currentPage+=1;
				queryVender();
			}
		}else{
			if(currentPage+1<=$("#ap").text()){
				currentPage=$("#ap").text();
				queryVender();
			}
		}
	}
	function jumpToPage(obj){
		goPage(obj.value);
}
</script>
</head>
<body><div id="main">
	<table width="100%"  border="0" cellpadding="0" cellspacing="0">
	  <tr>
	    <td nowrap class="title1">您的位置：工作台面－－采购管理－－新添采购单</td>
	  </tr>
	</table>
	<table width="100%"  border="0" cellpadding="0" cellspacing="0">
	  <tr>
	    <td width="30px" nowrap class="toolbar">&nbsp;</td>
	    <td width="40px" nowrap class="toolbar" onMouseOver="OMO(event)" onMouseOut="OMOU(event)">
	    <a href="../../gztm/pomain_add.jsp?op=add"><img src="../../images/new.gif">新增</a></td>
		<td class="toolbar">
			<form action="ListNewPomain">
			 	<input placeholder="采购单编号" type="text" name="poId"/>
			 	供应商：<input type="text" size="15" name="venderName" onclick="showVender()"/><input type="text" name="venderCode" hidden/>
				付款方式：<select name="payType"><option></option><option>货到付款</option><option>款到发货</option><option>预付款到发货</option></select>
				<input type="text" placeholder="开始日期" name="startDate" class="Wdate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,readOnly:true})" />
				<input type="text" placeholder="截止日期" name="endDate" class="Wdate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,readOnly:true})" />
				<input type="submit" value="根据条件查找"/>
			</form>
	  	</td>
	  </tr>
	</table>
	<table width="100%"  border="0" align="center" cellspacing="1" class="c">
		<tr>
			<td class="title1">采购单编号</td>
			<td class="title1">创建日期</td>
			<td class="title1">供应商名称</td>
			<td class="title1">创建用户</td>
			<td class="title1">附加费用</td>
			<td class="title1">采购产品总价</td>
			<td class="title1">采购单总价格</td>
			<td class="title1">付款方式</td>
			<td class="title1">最低预付款金额</td>
			<td class="title1">操作</td>
		</tr>
		<c:forEach items="${page.dataList}" var="pomain">
			  <tr>
			    <td align="center">${pomain.poId }</td>
			    <td align="center">${pomain.createTime }</td>
				<td align="center">${pomain.venderName }</td>
				<td align="center">${pomain.account }</td>
			    <td align="center">${pomain.tipFee }</td>
			 
			    <td align="center">${pomain.productTotal }</td>
			    <td align="center">${pomain.poTotal }</td>
			    <td align="center">
				    <c:if test="${pomain.payType==1 }">货到付款</c:if>
				    <c:if test="${pomain.payType==2 }">款到发货</c:if>
				    <c:if test="${pomain.payType==3 }">预付款到发货</c:if>
			    </td>
			    <td align="center">${pomain.prePayFee }</td>
			    <td align="center">
			    	<a href="QueryPomainDetail?poId=${pomain.poId }">修改</a>
			     	<a onclick="del(this)">删除</a> 
			     	<a href="ShowAllPomainDetail?poId=${pomain.poId }">查看</a>
			    </td>
			  </tr>
  		</c:forEach>
	</table><br/>
	<center>
 	当前第${page.currentPage}页 ，每页显示${page.pageSize }数据
    
    <c:if test="${page.currentPage == 1}">
    	<input type="button" value="首页" disabled="disabled"/>
    	<input type="button" value="上一页" disabled="disabled"/>
    </c:if>
    <c:if test="${page.currentPage != 1}">
	    <input type="button" value="首页" onclick="goPage(1)"/>
	    <input type="button" value="上一页" onclick="goPage(${page.currentPage-1})"/>
    </c:if>
    <c:if test="${page.currentPage == page.pageCount }">
	    <input type="button" value="下一页" disabled="disabled"/>
	    <input type="button" value="末页" disabled="disabled"/>
    </c:if>
    <c:if test="${page.currentPage != page.pageCount }">
	    <input type="button" value="下一页" onclick="goPage(${page.currentPage+1})"/>
	    <input type="button" value="末页" onclick="goPage(${page.pageCount})"/>
    </c:if>
    
    
          共${page.pageCount }页 ${page.totalCount }条记录
          &nbsp;前往第<select onchange="jumpToPage(this)"><c:forEach var="p" begin="1" end="${page.pageCount }">
    	<c:if test="${p==page.currentPage }"><option selected>${p}</option></c:if>
    	<c:if test="${p!=page.currentPage }"><option>${p}</option></c:if>
    </c:forEach></select>页
   </center>
   </div>
   <div hidden id="vender">
	<table width="100%"  border="0" align="center" cellspacing="1" id="venderTable">
	  <tr>
	    <td class="toolbar"> 供应商编号 </td>
	    <td class="toolbar"> 供应商名称 </td>
	    <td class="toolbar"> 操作 </td>
	  </tr>
	  <tbody id="tvender">
	  	
	  </tbody>
	</table>
	<center><br/>
	<input type="button" value="首页" onclick="vendergoPage('first')"/>
	<input type="button" value="上一页" onclick="vendergoPage('front')" />
	<input type="button" value="下一页" onclick="vendergoPage('next')"/>
	<input type="button" value="末页" onclick="vendergoPage('end')"/>
	当前第<span id="vc"></span>页
    	共<span id="va"></span>页
    <input type="button" value="返回" onclick="goback()"/>
	</center>
</div>
</body>
</html>